home *** CD-ROM | disk | FTP | other *** search
- Path: druid.borland.com!usenet
- From: pete@borland.com (Pete Becker)
- Newsgroups: comp.lang.c
- Subject: Re: A weird thing about printf()
- Date: 10 Apr 1996 15:23:18 GMT
- Organization: Borland International
- Message-ID: <4kgjp6$6lm@druid.borland.com>
- References: <4kflr2$5if@dewey.csun.edu>
- NNTP-Posting-Host: pbecker.borland.com
- Mime-Version: 1.0
- Content-Type: Text/Plain; charset=ISO-8859-1
- X-Newsreader: WinVN 0.99.5
-
- In article <4kflr2$5if@dewey.csun.edu>, kc44097@csun.edu says...
- >
- >
- >
- > The program :
- >
- >#include <stdio.h>
- >
- >int answer;
- >main()
- >{
- > answer=2+2;
- > printf("The answer is %d\n");
- > return 0;
- >}
- >
- > In printf(),I lost "answer" in the end,but it works,and give me the
- >result 0.I wonder how the compiler handle this condition.Also,is this
- >allow by C?(by this, I mean is this a leagal usage in language itself,
- >or just a mistake cause by the compiler?)
-
- Yes, this is legal. printf() takes a variable number of arguments, and the
- compiler is not required to check for consistency between the string you pass
- as the first argument and the number of arguments you actually pass. printf
- looked at the place where the next argument would have been. This will usually
- result in nonsensical output.
-
-